package com.ruoyi.hyg.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hyg.domain.SearchResult;
import com.ruoyi.hyg.service.ISearchService;

/**
 * 搜索Controller
 * 
 * @author hyg
 * @date 2025-01-XX
 */
@RestController
@RequestMapping("/hyg/search")
public class SearchController extends BaseController
{
    @Autowired
    private ISearchService searchService;

    /**
     * 根据课程名称模糊查询题库信息
     */
    @GetMapping("/questionBanks")
    public TableDataInfo searchQuestionBanks(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize)
    {
        startPage();
        List<SearchResult> list = searchService.searchQuestionBanks(keyword);
        return getDataTable(list);
    }

    /**
     * 获取热门课程
     */
    @GetMapping("/hotCourses")
    public AjaxResult getHotCourses()
    {
        List<SearchResult> list = searchService.getHotCourses();
        return success(list);
    }

    /**
     * 获取搜索建议（自动补全）
     */
    @GetMapping("/suggestions")
    public AjaxResult getSearchSuggestions(@RequestParam("keyword") String keyword)
    {
        List<String> suggestions = searchService.getSearchSuggestions(keyword);
        return success(suggestions);
    }
}
